<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">积分日志</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>积分日志</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <form class="layui-form toolbar" name="queryForm">
            <div class="layui-inline">
                用户昵称：
                <input name="nickName" type="text" class="layui-input search-input enterSubmit" placeholder="请输入">
            </div>
            &nbsp;&nbsp;
            <div class="layui-inline">
                类型：
                <select id="pointsRuleType" name="prtype">
                    <option value="">-请选择规则类型-</option>
                </select>&emsp;
            </div>
            &nbsp;&nbsp;
            <div class="layui-inline">
                创建时间
                <div class="layui-input-inline" style="width: 150px;">
                    <input type="text" name="startDate" class="layui-input" id="startDate" placeholder="开始时间">
                </div>
                <!--<div class="layui-form-mid">-</div>-->
                <div class="layui-input-inline" style="width: 150px;">
                    <input type="text" name="endDate" class="layui-input" id="endDate" placeholder="结束时间">
                </div>
            </div>
            &nbsp;&nbsp;
            <button id="points-btn-search" class="layui-btn icon-btn" lay-submit lay-filter="query"><i
                    class="layui-icon">&#xe615;</i>搜索
            </button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <!--<button id="points-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>-->
        </form>

        <!-- 数据表格 -->
        <table class="layui-table" id="pointsLog-table" lay-filter="pointsLog-table"></table>
    </div>
</div>
<script>
    layui.use(['form', 'table', 'util', 'config', 'admin','laydate'], function () {
        let form = layui.form;
        let table = layui.table;
        let config = layui.config;
        let layer = layui.layer;
        let util = layui.util;
        let admin = layui.admin;
        let laydate = layui.laydate;
        //日期时间范围
        laydate.render({
            elem: '#startDate'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#endDate'
            , type: 'datetime'
        });

        let url = config.base_server + 'api-points/pointsLog/getPointsLog';
        let params = {
            access_token: config.getToken().access_token
        };
        let cols = [[
            {type: 'numbers'},
            {field: 'plogid', sort: true, title: 'ID', width: 100},
            {field: 'nickName', sort: true, title: '用户昵称', align: 'center'},
            {field: 'porule', sort: true, title: '规则描述', align: 'center'},
            {field: 'prtyne', sort: true, title: '规则类型', align: 'center'},
            {field: 'points', sort: true, title: '积分值', align: 'center'},
            {
                field: 'cretim', sort: true, align: 'center', templet: function (d) {
                    return util.toDateString(d.cretim);
                }, title: '创建时间'
            },
        ]];

        // 渲染表格
        table.render({
            elem: '#pointsLog-table',
            url: url,
            where: params,
            page: true,
            cols: cols
        });

        // // 工具条点击事件
        // table.on('tool(pointsLog-table)', function (obj) {
        //     let data = obj.data;
        //     let layEvent = obj.event;
        //     if (layEvent === 'edit') {
        //         showEditModel(data);
        //     } else if (layEvent === 'del') {
        //         layer.confirm('此操作不可逆，确定删除吗？', function () {
        //             layer.load(2);
        //             admin.req('api-points/pointsRule/' + obj.data.poruid, {}, function (data) {
        //                 layer.closeAll('loading');
        //                 if (data.code === 0) {
        //                     layer.msg(data.msg, {icon: 1, time: 500});
        //                     table.reload('pointsLog-table', {});
        //                 } else {
        //                     layer.msg(data.msg, {icon: 2, time: 500});
        //                 }
        //             }, 'DELETE');
        //
        //         });
        //     }
        // });

        // 填充下拉列表 - 积分规则类型
        admin.req('api-points/pointsRuleType/get', {}, (data) => {
            $.each(data.data, function (index, item) {
                let option = new Option(item.prtyne, item.prtycd);
                $("select[name='prtype']").append(option);
            });
            form.render();
        }, 'GET');

        // // 添加按钮点击事件
        // $('#points-btn-add').click(function () {
        //     showEditModel();
        // });


        // 条件检索
        form.on('submit(query)', (data) => {
            table.reload('pointsLog-table', {where: data.field});
            return false;
        });


        // 回车查询
        $('.enterSubmit').keyup((e) => {
            switch (e.keyCode) {
                case 13:
                    $('#points-btn-search').click();
                    break;
            }
        });
    });
</script>